<template>
  <div class></div>
</template>
<script>
import axios from "@/utils/requestdp";
import dayjs from 'dayjs';

export default {
  name: "APIqueryDbPipenetColSa_003qczz",
  components: {},
  data() {
    return {};
  },
  computed: {
    ishistory: function() {
      return this.$store.state.daping.ishistorytime;
    },
    timerangarr: function() {
      return this.$store.state.daping.timepick;
    }
  },
  watch: {
    "$store.state.daping.bigScreen": {
      handler: function(n, o) {
        this.watchEvent();
      }
    }
  },
  mounted() {},
  methods: {
    watchEvent() {
      //先清除定时任务
      if (
        this.$store.state.daping.intervalArr["APIqueryDbPipenetColSa_003qczz"] !=
        undefined
      ) {
        return;
      }
      let n_tmp = this.$store.state.daping.bigScreen;
      let g_bigscreen_data_arr = n_tmp.filter(item => {
        if (item.attrName == "echart_plan_heat") {
          return true;
        }
      });
      this.loadData(g_bigscreen_data_arr[0].attrValue);
      let interval = setInterval(() => {
        let n_tmp = this.$store.state.daping.bigScreen;
        let g_bigscreen_data_arr = n_tmp.filter(item => {
          if (item.attrName == "echart_plan_heat") {
            return true;
          }
        });
        this.loadData(g_bigscreen_data_arr[0].attrValue);
      }, this.$root.setting.data.interval);
      this.$store.state.daping.intervalArr["APIqueryDbPipenetColSa_003qczz"] = [
        { interval: interval }
      ];
    },
    loadData(val) {
      // 判断当前时刻是否超过晚八点
      var nowHour = new Date().getHours();
      let startTime;
      let etime = dayjs().format('YYYY-MM-DD');
      var day = new Date();
      if (nowHour < 20) {
        let yestoday = day.setTime(day.getTime()-24*60*60*1000);
        startTime = dayjs(dayjs(yestoday).format('YYYY-MM-DD') + " 20:00:00").unix();
      } else {
        startTime = dayjs(dayjs().format('YYYY-MM-DD') + " 20:00:00").unix();
      }
      let queryJson = {
        startTime,
        endTime: dayjs().unix(),
        table: 'pipenet_m',
        type: 'history',
        orderBy: 'aligntime',
        search: 'id=0',
        queries: [
          {
            metric: 'id,sa_003qc',
            schema: 'dwb'
          }
        ]
      }
      // 查询全网供热量
      // axios.post("/open/queryDb", queryJson).then(res => {
      //   if (res.data.length) {
      //     //如果有则获取200中的结果
      //     this.$store.state.daping.queryDbPipenetColSa_003qc_zz = res.data;
      //   } else {
      //     //如果没有则提示错误信息 置空对象
      //     console.log("参数有误", data);
      //   }
      // });

      let yestodayFormat = dayjs(dayjs().add(-1, 'day')).format('YYYY-MM-DD')
      if (nowHour < 8) {
        // 查询全网买热量
        Promise.all([axios.post("/open/queryDb", queryJson), axios.get(`heatPlan/planData?planDate=${yestodayFormat}`)]).then(res => {
          this.$store.state.daping.queryDbPipenetColSa_003qc_zz = res
        })
      } else {
        // 查询全网买热量
        Promise.all([axios.post("/open/queryDb", queryJson), axios.get(`heatPlan/planData?planDate=${yestodayFormat}`), axios.get(`heatPlan/planData?planDate=${dayjs().format('YYYY-MM-DD')}`)]).then(res => {
          this.$store.state.daping.queryDbPipenetColSa_003qc_zz = res
        })
      }

      
    }
  }
};
</script>
<style lang='scss' scoped>
</style>